<?php
header("Content-type:text/html; charset=utf8");
include("function.php");
judgeLogin();
include('page.php');
//$page = new page($num_list,10);
//$str=$page->getPage();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="食品笔记,食品,食品安全,饮食,饮食安全,生活"><!--SEO关键字-->
<meta name="description" content="食品笔记，你的饮食安全卫士"><!--SEO描述-->
<link rel="shortcut icon" type="image/ico" href="images/favicon.ico"><!--选项卡图标-->
<title>食品笔记 - 让生活更健康</title>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/style.css">

<!--[if ie]>
<link rel="stylesheet" href="css/ie.css">
<script type="text/javascript" src="js/DD_belatedPNG.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('.png');/*在需要png透明的元素里面加上.png样式即可（class="png"）*/
</script>
<![endif]-->
</head>
<body>
	<div class="header w pr"><!-- header -->
		<div class="index-header w960 bc pr">
			<a href="home.php" class="score_logo score_img dib png fl mt10"></a>
			<div class="header_right fr">
				<ul class="header_nav fl tc fb f12 h">
					<li><a href="home.php">首 页</a></li>
					<li><a href="report.php">饮食报告</a></li>
					<li><a href="newsmap.php">食品新闻</a></li>
					<li><a href="food.php">选食专栏</a></li>
					<li><a href="timeline.php">时光轴</a></li>
					<li><a href="share.php" class="header_nav_hover">分享</a></li>
				</ul>
				<a href="massage.php" class="header_myMessage tc fr ml5" title="私信"><?php echo showCountMassage($_SESSION['login_mail']);?></a><!-- 私信 -->
				
				<div class="header_myInfo fr f14 h pr">
					<a href="#" class="header_setup"><img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="fl" /></a><!-- user_avatar -->
					<a href="#" class="fl header_setup"><?php echo showUserName();?></a><!-- user_nickname -->
					<div class="header_myInfoArrow score_img fl"></div>
					<ul class="header_hideInfo none pa tc w"><!-- hide_info -->
						<li><a href="#" class="header_setup">个人设置</a></li>
						<li><a href="modifymail.php">修改邮箱</a></li>
						<li><a href="password.php">修改密码</a></li>
						<li><a href="login_out.php">退出登录</a></li>
					</ul>
				</div>
				
			</div>
			<div class="score_img content_top pa"></div>
		</div>
	</div><!-- end_header -->

	<div class="score_main pr oh h"><!-- score_main -->
		<div class="main w960 bc h">
			<div class="score_sider fl mt20">
				<div class="main_avatar">
					<img src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" class="score_avater mb20" /><!-- main_avatar -->
					<p><a href="#" class="score_nickname f18 fb header_setup"></a> | <a href="massage.php" class="sider_message">私信(<?php echo showCountMassage($_SESSION['login_mail']);?>)</a></p><!-- main_nickname -->
				</div>
			</div>
			<div class="content fr pr">
				<ul class="share_nav ml30 oh">
					<li class="fl w100 tc share_selected">所有笔记</li>
					<li class="fl w100 tc">我的笔记</li>
				</ul>
				
				<div class="share_contents ml30 pt20 pb20"><!-- 这是“所有笔记”里面的内容，“我的笔记”内结构与“所有笔记”一致 -->
				<?php
				$sql_bbs = "select *,DATE(create_time) as time from food_bbs order by id desc";
				$page = new Page('',$sql_bbs,$_GET['page'],7,"?page=");  
				$rows = $page->list;  
				foreach($rows as $row_bbs) 
				{
				
					$time = $row_bbs['time'];
					$user_id = $row_bbs['user_id'];
					$sql_list = "select * from food_user_data where user_id = '$user_id' and history_data = '0' and create_time like '$time%'";
					$query_list = mysql_query($sql_list) or die(mysql_error());
				
					$sql_user = "select * from food_user_basic where id = '$user_id'";
					$query_user = mysql_query($sql_user) or die(mysql_error());
					$row_user = mysql_fetch_array($query_user);
					//echo $row_user['user_mail'];
				?>
					<div class="share_single ml20 oh pb20 mb20"><!-- 每一条分享内容 -->
<div class="fl share_avatar mr20"><img height="63px" width="63px" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo shareUserPhoto($row_user['user_mail']);endif;?>" alt="" /></div><!-- 头像 63X63 -->
						<div class="share_listTop fl oh">
							<div class="share_detailed fl">
								<h3 class="mb20 share_username f12"><a href=""><?php echo $row_user['nick'];?></a></h3><!-- 分享者用户名 -->
								<table>
									<tr>
										<td class="share_title">我的食谱：</td>
										<td class="pb20 share_foodDetail"><!-- 当天所记录食品，“-”后面接重量 -->
											<?php
											while($row_list = mysql_fetch_array($query_list))
											{
											?>
											<span><a href=""><?php echo $row_list['eatwhat'];?></a> -<?php echo $row_list['eathowmany'];?></span>
											<?php 
											}
											?>
											
										</td>
									</tr>
									<tr>
										<td class="share_title">主人寄语：</td>
										<td class="pb20 share_foodDetail"><?php echo $row_bbs['content'];?></td><!-- 用户分享留言 -->
									</tr>
								</table>
							</div>
							<div class="share_score fr w100 h100 f12 tc">
								<?php 
								$sql_score = "select user_score from food_user_score where user_id = '$user_id' and create_time like '$time%'";
								$query_score = mysql_query($sql_score) or die(mysql_error());
								$row_score = mysql_fetch_array($query_score);
								?>
								<div class="share_finalScore"><?php echo $row_score['user_score'];?></div><div class="share_scoreTip">Your score</div>
							</div>
						</div>
						<div class="share_parts">
							<input type="hidden" value="<?php echo $row_bbs['id'];?>" class="bbs_id">
														<span class="mr20 dib"><?php echo $time; ?></span><a href="javascript:void(0)" class="dib share_vote"><?php echo $row_bbs['vote'];?>人觉得很赞</a>
						</div>
					</div>
				<?php
				}
				?>
				<div style="margin-left:150px;">
				<?php
				echo $page->getPageList();  //输出分页列表 
				?>
				</div>
				</div>



				
				<div class="share_contents ml30 pt20 pb20 none"><!-- 这是“我的笔记”里面的内容，“我的笔记”内结构与“所有笔记”一致，多了一个none类 -->
				<?php
				$self_id = getUserId($_SESSION['login_mail']);
				$sql_bbs = "select *,DATE(create_time) as time from food_bbs where user_id = '$self_id' order by id desc";
				$query_bbs = mysql_query($sql_bbs);
				while($row_bbs = mysql_fetch_array($query_bbs))
				{
				
					$time = $row_bbs['time'];
					$user_id = $row_bbs['user_id'];
					$sql_list = "select * from food_user_data where user_id = '$user_id' and history_data = '0' and create_time like '$time%'";
					$query_list = mysql_query($sql_list) or die(mysql_error());
				
					$sql_user = "select * from food_user_basic where id = '$user_id'";
					$query_user = mysql_query($sql_user) or die(mysql_error());
					$row_user = mysql_fetch_array($query_user);
				?>
					<div class="share_single ml20 oh pb20 mb20"><!-- 每一条分享内容 -->
						<div class="fl share_avatar mr20"><img  height="63px" width="63px" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" alt="" /></div><!-- 头像 63X63 -->
						<div class="share_listTop fl oh">
							<div class="share_detailed fl">
								<h3 class="mb20 share_username f12"><a href=""><?php echo $row_user['nick'];?></a></h3><!-- 分享者用户名 -->
								<table>
									<tr>
										<td class="share_title">我的食谱：</td>
										<td class="pb20 share_foodDetail"><!-- 当天所记录食品，“-”后面接重量 -->
											<?php
											while($row_list = mysql_fetch_array($query_list))
											{
											?>
											<span><a href=""><?php echo $row_list['eatwhat'];?></a> -<?php echo $row_list['eathowmany'];?></span>
											<?php 
											}
											?>
											
										</td>
									</tr>
									<tr>
										<td class="share_title">主人寄语：</td>
										<td class="pb20 share_foodDetail"><?php echo $row_bbs['content'];?></td><!-- 用户分享留言 -->
									</tr>
								</table>
							</div>
							<div class="share_score fr w100 h100 f12 tc">
								<?php 
								$sql_score = "select user_score from food_user_score where user_id = '$user_id' and create_time like '$time%'";
								$query_score = mysql_query($sql_score) or die(mysql_error());
								$row_score = mysql_fetch_array($query_score);
								?>
								<div class="share_finalScore"><?php echo $row_score['user_score'];?></div><div class="share_scoreTip">Your score</div>
							</div>
						</div>
						<div class="share_parts">
						
							<input type="hidden" value="<?php echo $row_bbs['id'];?>" class="bbs_id">
							<span class="mr20 dib"><?php echo $time; ?></span><a href="javascript:void(0)" class="dib share_vote"><?php echo $row_bbs['vote'];?>人觉得很赞</a><!-- 投票功能 -->
						</div>
					</div>
				<?php
				}
				?>
					
				</div>
				
			</div>
		</div>
	</div><!-- end_score_main -->

	<div class="footer w"><!-- footer -->
		<div class="w960 bc pr">
			<div class="content_footer score_img pa"></div>
			<div class="pt30 welcome-footer bc">
				<span class="iphone-app-img dib png fl"></span><a href="#" class="iphone-app f12 a3 fl">iphone应用</a><a href="foodnote.apk" class="android-app f12 a3 fr">android应用</a><span class="android-app-img dib png fr"></span>
			</div>
			<div class="welcome-about mb10">
				<p class="f12 tc"><a href="#" class="a3">关于我们</a><span class="ml10 mr10">|</span><a href="#" class="a3">使用条款</a><span class="ml10 mr10">|</span><a href="#" class="a3">常见问题</a></p>
			</div>
			<div class="welcome-about f12 tc">
				<p class="a3 f12 c91">Copyright &copy; 2011-2012 Foodnote&nbsp;&nbsp;&nbsp;&nbsp; 湘ICP备09004495号-5</p>
			</div>
		</div>
	</div><!-- end_footer -->
	
	<?php
		//判断是否新用户登录
		$login_mail = $_SESSION['login_mail'];
		$login_status = judgeNewUser($login_mail);
		
		//获取用户数据
		$userData = getUserBasicInfo($_SESSION['login_mail']);
		
		if($login_status == 0)
		{
			echo "<div class='novice_login png pa w'>";
		}else
		{
			echo "<div class='novice_login png pa w none'>";
		}
	?>
		<div class="personal_info bc oh pb50 pr">
			<div class="personal_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">个人信息录入</h2>
			
			<form action="home.php" method="post" class="ml50">
				<fieldset class="fl">
					<p class="mt10"><label for="" class="personal_label f22">性别</label></p>
					<p class="mt10"><small class="personal_small f14">请选择：男/女</small></p>
					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="sex">
					<?php  
						if($userData['user_sex']=="男"):
						
							echo "<option value='男' selected >男</option>";
							echo "<option value='女'>女</option>";
						
						elseif($userData['user_sex']=="女"):
						
							echo "<option value='男'>男</option>";
							echo "<option value='女' selected>女</option>";
						
						else:
						
							echo "<option value='' selected>--</option>";
							echo "<option value='男'>男</option>";
							echo "<option value='女'>女</option>";
						endif;
					?>
								
						</select>
					</p>
					<p class="mt10"><label for="" class="personal_label f22">年龄</label></p>
					<p class="mt10"><small class="personal_small f14">不同的年龄对饮食的需求不同，例如:23</small></p>
					<p class="mt10"><input type="text" class="score_text zy_ageVal pl5 pr5" name="age" value="<?php echo $userData['user_age'];?>"/></p>
					<p class="mt10"><label for="" class="personal_label f22">现居地</label></p>
					<p class="mt10"><small class="personal_small f14">请输入您现居地的省份名，例如:湖南</small></p>

					<p class="mt10">
						<select class="score_text score_select pl5 pr5 " name="city">
							<option value='<?php echo $userData['user_city'];?>' selected><?php echo $userData['user_city'];?></option>
							<option value='安徽'>安徽</option>
							<option value='福建'>福建</option>
							<option value='港澳台藏'>港澳台藏</option>
							<option value='甘肃'>甘肃</option>
							<option value='广东'>广东</option>
							<option value='广西'>广西</option>
							<option value='贵州'>贵州</option>
							<option value='海南'>海南</option>
							<option value='河北'>河北</option>
							<option value='黑龙江'>黑龙江</option>
							<option value='河南'>河南</option>
							<option value='湖北'>湖北</option>
							<option value='湖南'>湖南</option>
							<option value='江苏'>江苏</option>
							<option value='江西'>江西</option>
							<option value='吉林'>吉林</option>
							<option value='辽宁'>辽宁</option>
							<option value='内蒙古'>内蒙古</option>
							<option value='宁夏'>宁夏</option>
							<option value='青海'>青海</option>
							<option value='山东'>山东</option>
							<option value='山西'>山西</option>
							<option value='陕西'>陕西</option>
							<option value='四川'>四川</option>
							<option value='云南'>云南</option>
							<option value='新疆'>新疆</option>
							<option value='浙江'>浙江</option>
							<option value='直辖市'>直辖市</option>
						</select>
					</p>

					<p class="mt10"><label for="" class="personal_label f22">体重</label></p>
					<p class="mt10"><small class="personal_small f14">不同的体重对饮食的需求不同，单位：kg</small></p>
					<p class="mt10"><input type="text" class="score_text zy_weightVal pl5 pr5" name="weight" value="<?php echo $userData['weight'];?>"/> kg</p>
					<input type="hidden" value="<?php echo basename($_SERVER['PHP_SELF']);?>" name="fileName" />
					<input type="hidden" value="true" name="submited" />
					<input type="submit" value="确认提交" name="submit" class="personal_submit pa f18" />
				</fieldset>
			</form>
			<form method="post" action ="upload.php" enctype="multipart/form-data" target="hidden_frame" class="none">
				<fieldset>
					<input type="file" name="photo" id="photo" onchange="cli('p_submit');"/>
					<input type="submit" name="p_submit" value="保存" id="p_submit">
					<iframe name='hidden_frame' id="hidden_frame" style="border:none;" onreadystatechange="reflesh('<?php echo $_SESSION[login_mail]?>');"></iframe>
				</fieldset>
			</form>
			<form action="home.php" method="post" class="ml50">
				<fieldset>
					<a href="javascript:void(0)" onclick="cli('photo');"><img id="img" src="<?php if(!empty($_SESSION['qq_nickname'])): echo $_SESSION['qq_photoUrl']; else: echo showUserPhoto();endif;?>" class="personal_avatar pa" />
					<span class="pa click_upload">+点击上传头像</span>
					</a>
					<a href="javascript:void(0)" class="pa avatar_refresh" onclick="reflesh('<?php echo $_SESSION[login_mail]?>');">刷新</a>
				</fieldset>
			</form>
		</div>
	</div>


	<?php //qq_state 
	$qq_status = qq_status($login_mail); 
	if(isset($_SESSION['qq_nickname']) && $qq_status == 0):
	?>
	<div class="qq_tips_bg png pa w"><!-- QQ登陆提醒 -->
		<div class="qq_tips bc oh pb50 pr">
			<div class="qq_close score_img pa"></div>
			<h2 class="personal_title ml50 mt20 mb20">温馨提示</h2>
			<div class="qq_tipsh oh ml50 f14">
				<img src="images/tips_smile.png" alt="" class="fr png mr150" /><!-- 提示图片 -->
				<p>亲爱的</span class="a69"><?php echo $_SESSION['qq_nickname']; ?></span></p>
				<input type="hidden" class="qq_user_mail" value="<?php echo $login_mail;?>">
				<p>欢迎来到<span class="a69">食品笔记</span></p>
				<p>你的登陆账号为:<?php echo $_SESSION['login_mail'];?></p>
				<p>密码为:<?php echo $_SESSION['user_prepassword'];?></p>
				<p>为了方便下次登录，请即时<a href="password.php">修改密码</a>。</p>
			</div>
		</div>
	</div>
	<?php endif;?>
	
	<div id="scroeLoading" class="none png">
		<div class="loadingCenter bc pr">
			<div class="scoreLoading_bar bc pr"><div class="scoreLoading_cover pa"></div></div>
			<p class="loadingTips mt20 bc tc"></p>
		</div>
	</div>
	
	<div class="shareWrap tc w h none"><!-- 分享板 -->
		<div class="shareBg pa h w png"></div>
		<div class="shareBoard vm w700 dib bc tl pr">
			<div class="shareHead mt20 bc oh">
				<h3 class="a3 f24 fl">分享</h3><span class="shareLimit fr">还可以输入 <strong class="">120</strong> 字</span>
			</div>
			<form action="" class="share_form bc mt5">
				<textarea name="" cols="30" rows="10" class="share_textarea"></textarea>
				<div class="shareFooter mt10 oh pb30">
					<span class="shareTip fl">经常登录<a href="www.foodnote.net/home.php">食品笔记</a>有益健康哦</span>
					<input type="submit" value="分享" class="shareBtn fr" />
				</div>
			</form>
		</div>
		<span class="verticalMiddle h vm dib"></span>
	</div>
	
	<!-- JavaScript -->
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="js/slider_bar.js"></script>
	<?php if(!empty($_SESSION['qq_nickname'])){ ?>
<script type="text/javascript">  
	$(document).ready(function(){
		$('.qq_tips').show();
		
		$('.qq_close').click(function(event){
			$('.qq_tips_bg').hide();
		});
	})
</script>
	<?php } ?> 
<script type="text/javascript">  
 
 function cli(id){  
		var sub = document.getElementById(id);
   sub.click();  
//   if (/msie/i.test(navigator.userAgent)) //IE  
//   {  
//      sub.fireEvent("onclick");  
//   } else {  
//      var e = document.createEvent('MouseEvent');  
//      e.initEvent('click', false, false);  
//      sub.dispatchEvent(e);  
//   }
}

function reflesh(user){
	image_src="image.php?user_mail="+user+"&math="+Math.random(1);
	//alert(image_src);
	document.getElementById("img").src=image_src;
	
	}	

</script> 
<div class="none">
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fbba169f4f4508eb5cc1c5618eeb3c59d' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
</body>

</html>
